#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

# This is the debhelper compatibility version to use.
export DH_COMPAT=4

PACKAGE := qhull

soversion  := 5
soname     := libqhull$(soversion)
instdir    := debian/$(soname)
destdir    := $(shell pwd)/debian/tmp
debdoc     := $(destdir)/usr/share/doc
debdoclib  := $(destdir)/usr/share/doc/$(soname)

include /usr/share/dpatch/dpatch.make

config: config-stamp
config-stamp:
	dh_testdir
	./configure --prefix=/usr --mandir=/usr/share/man
	touch config-stamp

build: build-stamp
build-stamp: patch config
	dh_testdir

	$(MAKE)

	( cd debian ; \
	  for info in "qconvex:compute the convex hull" \
	              "qdelaunay:compute the Delaunay triangulation" \
	              "qhalf:halfspace intersection about a point" \
	              "qvoronoi:compute the Voronoi diagram" ; do \
	    comm=`echo  $$info | cut -d: -f1` ; \
	    purp=`echo  $$info | cut -d: -f2` ; \
	    eperl -d command=$$comm -d purpose="$$purp" -d soname=$(soname) \
	      manpage.in > $$comm.sgml ; \
	    docbook2man $$comm.sgml ; \
	  done )

	touch build-stamp

clean: unpatch
	dh_testdir
	dh_testroot

	-$(MAKE) distclean
	( cd debian ; rm -rf *.sgml *.1 manpage.links manpage.refs )

	rm -f install-stamp build-stamp config-stamp patch-stamp

	dh_clean

install: install-stamp
install-stamp: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(MAKE) install DESTDIR=$(destdir)
	rm -f $(debdoc)/qhull/COPYING.txt
	mv $(debdoc)/qhull/Changes.txt $(debdoc)/qhull/changelog

	mv $(debdoc)/qhull $(debdoclib)
	for i in libqhull-dev qhull-bin ; do \
	  mkdir -p debian/$$i/usr/share/doc ; \
	  ln -s $(soname) debian/$$i/usr/share/doc/$$i ; \
	done

	chmod +x debian/install-src-html.sh
	debian/install-src-html.sh $(debdoclib)/src

	dh_movefiles --no-package=$(soname)
	dh_movefiles --package=$(soname)

	dh_installman --package=qhull-bin debian/*.1

	touch install-stamp

# Build architecture-independent files here.
binary-indep:

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs -p$(soname) debian/copyright
	dh_installchangelogs -p$(soname)
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install config \
        patch unpatch
